import { Injectable } from '@angular/core';
import {
  HttpEvent, HttpInterceptor, HttpHandler, HttpRequest,HttpResponse
} from '@angular/common/http';

import { Observable } from 'rxjs';


/** Pass untouched request through to the next request handler. */
@Injectable()
export class NoopInterceptor implements HttpInterceptor {

  intercept(req: HttpRequest<any>, next: HttpHandler):
    Observable<HttpEvent<any>> {
        console.log("所有请求都会经过这里")
           // Get the auth token from the service.
    const authToken = window.localStorage.getItem("auth_token")
    // Clone the request and replace the original headers with
    // cloned headers, updated with the authorization.
    const authReq = req.clone({
      headers: req.headers.set('X-Access-Token', authToken)
    });

    // send cloned request with header to the next handler.
    return next.handle(authReq);
  }
// 拦截请求结果
  afterResponse(res:Observable<Response>):Observable<any>{

    res.subscribe( data=> {
      if ( data.status === 401){

      };
    })

    return res ;
  }
}
